import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ichinesereader/controller/assessments.dart';
import 'package:ichinesereader/models/assessment/assessmentRecordsResult.dart';
import 'package:ichinesereader/utils/log.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:ichinesereader/widgets/grids/assessmentBooksDataGrid.dart';
import '../../themes/pageStyles.dart';

class AssessmentBookRecords extends StatefulWidget {
  @override
  State<AssessmentBookRecords> createState() => _AssessmentBookRecordsState();
}

class _AssessmentBookRecordsState extends State<AssessmentBookRecords> {
  final box = Hive.box('appconfig');
  final AssessmentsController controller = Get.find();
  var questionRecords = <QuestionRecord>[];

  @override
  void initState() {
    ////     controller.fetchAssessmentQuizbookRecords(
    ////     '0', '0', 'AP,SOCIAL_STUDIES,EVALUATION,BENCHMARK_TEST');
    Future.delayed(
        Duration(milliseconds: 100),
        (() => controller
                .fetchAssessmentQuizbookRecords('0', '0', 'AP,SOCIAL_STUDIES')
                .then((records) {
              setState(() {
                questionRecords = records;
              });
            })));
    super.initState();
  }

  @override
  void dispose() {
    controller.questionRecords.clear();
    super.dispose();
  }

  final PageStyles _pageStyles = PageStyles();

  @override
  Widget build(BuildContext context) {
    Log.debug('build assessment books records tab');

    return Container(
      decoration: _pageStyles.dataGridBackground(),
      child: Container(
        margin: EdgeInsets.all(12.0),
        decoration: _pageStyles.dataGridForground(),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Expanded(child: AssessmentBooksDataGrids(questionRecords, false)),
            // controller.obx(
            //   (data) => Expanded(
            //       child: AssessmentBooksDataGrids(
            //           controller.questionRecords, false)),
            //   onEmpty: Expanded(
            //       child: AssessmentBooksDataGrids(
            //           controller.questionRecords, false)),
            // ),
          ],
        ),
      ),
    );
  }
}
